package com.nidu.demo.oauth2.executor.query;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.exception.BizException;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import com.nidu.demo.oauth2.convertor.OAuth2ClientConvertor;
import com.nidu.demo.oauth2.dto.OAuth2ClientCO;
import com.nidu.demo.oauth2.gateway.OAuth2ClientGateway;
import com.nidu.demo.oauth2.model.OAuth2Client;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class OAuth2ClientSingleQryExe {

    private final OAuth2ClientGateway gateway;

    private final OAuth2ClientConvertor convertor;

    public SingleResponse<OAuth2ClientCO> execute(Long id) {
        OAuth2Client auth2Client = gateway.getById(id);
        if(auth2Client == null){
            throw new BizException(ErrorCodeConstants.OAUTH2_CLIENT_NOT_FOUND.getCode(), ErrorCodeConstants.OAUTH2_CLIENT_NOT_FOUND.getMessage());
        }
        return SingleResponse.of(convertor.toClientObject(auth2Client));
    }

}
